﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using XQ.RequestOfficeSupplies.BLL.Sys;
using XQ.RequestOfficeSupplies.WebAPI.Models;

namespace XQ.RequestOfficeSupplies.WebAPI.Controllers.System
{
    /// <summary>
    /// 行政区划API
    /// </summary>
    public class AreaController : ApiController
    {
        AreaBLL areaBLL = new AreaBLL();

        /// <summary>
        /// 获取指定父节点的所有下级行政区划(顶级区划为父ID为0)
        /// </summary>
        /// <param name="parentID"></param>
        /// <returns></returns>
        [Route("API/Area/GetAreaList")]
        [HttpGet]
        public ResultModel GetAreaList(long parentID)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                resultModel.data = areaBLL.GetAreaList(parentID);
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.message = ex.Message;
                resultModel.code = "10001";
            }

            return resultModel;
            
        }


        /// <summary>
        /// 根据身份证获取学生籍贯
        /// </summary>
        /// <returns></returns>
        [Route("api/Area/GetNativePlaceByIDNumber")]
        [HttpGet]
        public ResultModel GetNativePlaceByIDNumber(string idNumber)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                if (!string.IsNullOrEmpty(idNumber) && idNumber.Length == 18)
                {
                    resultModel.data = areaBLL.GetNativePlaceByIDNumber(idNumber);
                }
                
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.message = ex.Message;
                resultModel.code = "10001";
            }

            return resultModel;
        }

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<controller>
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<controller>/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }
    }
}